# Copyright 1999-2012 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
# $Header: app-misc/2gis-data/2gis-data-2012.11.ebuild,v 1.0 2012/11/11 15:25:00 itspec.ru Exp $

EAPI="4"

inherit eutils

DESCRIPTION="Proprietary freeware multimedia map of several Russian and Ukrainian towns (data)"
HOMEPAGE="http://2gis.ru"

LICENSE="2Gis-ru"
RESTRICT="mirror"

SLOT="0"
KEYWORDS="~x86 ~amd64"

DEPEND="app-arch/unzip"
RDEPEND=">=app-misc/2gis-3.10.0.1"

# filled in `use_prepare` from file
IUSE=""
SRC_URI=""

S="${WORKDIR}"

use_prepare() {
    # FILESDIR variable not accessable
    local filesdir="${PORTDIR_OVERLAY}/${CATEGORY}/${PN}/files"
    local line
    local useflag
    local link

    while read line; do
        useflag="$(echo $line | cut -f 1 -d " ")"
        link="$(echo $line | cut -f 2 -d " ")"
        SRC_URI="${SRC_URI} ${useflag}? ( ${link} )"
        IUSE="${IUSE} ${useflag}"
    done < "${filesdir}"/use-links-${PV}.txt
}

use_prepare

src_install() {
    insinto /opt/2gis
    # Only attempt to install any data if the user has enabled at least
    # one useflag.
    if [ -d 2gis/3.0 ]; then
        # Only required data files were unpacked, so it should be safe
        # to use wildcard.
        doins -r 2gis/3.0/* || die
    fi
}
